package com.codi.bus.core.service.util;

import com.codi.base.util.EqualsUtil;
import com.codi.bus.constant.FundConst;
import com.codi.bus.constant.GlobalConstant;
import com.codi.fundData.domain.FundNetValuePerformance;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;

/**
 * 基金相关工具类
 *
 * @author shi.pengyan
 * @date 2016年11月16日 上午10:38:56
 */
@Slf4j
public final class FundUtil {

    /**
     * 判断基金类型编码是否是货币<br/>
     * 短期理财表现形式为货基
     *
     * @param fundTypeCode
     * @return
     */
    public static boolean isCurrency(Integer fundTypeCode) {
        if (fundTypeCode == null) {
            return false;
        }
        switch (fundTypeCode.intValue()) {
            case FundConst.FUND_TYPE_CODE_CURRENCY:
            case FundConst.FUND_TYPE_CODE_SHORT_TERM_FINANCING:
                return true;
            default:
                ;
        }

        return false;
    }

    /**
     * 获取统计类型最终字段
     *
     * @param statisType 对外公开的标识
     * @return
     */
    public static String getStatisType(Integer statisType) {
        switch (statisType) {
            case 0:
                return "NVDailyGrowthRate";
            case 1:
                return "RRInSingleWeek";
            case 2:
                return "RRInSingleMonth";
            case 3:
                return "RRInThreeMonth";
            case 4:
                return "RRInSixMonth";
            case 5:
                return "RRInSingleYear";
            case 6:
                return "RRInTwoYear";
            case 7:
                return "RRInThreeYear";
            case 8:
                return "RRSinceThisYear";
            case 9:
                return "RRSinceStart";
            default:
                return "NVDailyGrowthRate";
        }
    }

    /**
     * 依据类型返回对应值
     *
     * @param netValue   净值类型
     * @param statisType 统计类型
     * @return
     */
    public static BigDecimal getStatisType(FundNetValuePerformance netValue, Integer statisType) {
        switch (statisType) {
            case 0:
                return netValue.getNVDailyGrowthRate();
            case 1:
                return netValue.getRRInSingleWeek();
            case 2:
                return netValue.getRRInSingleMonth();
            case 3:
                return netValue.getRRInThreeMonth();
            case 4:
                return netValue.getRRInSixMonth();
            case 5:
                return netValue.getRRInSingleYear();
            case 6:
                return netValue.getRRInTwoYear();
            case 7:
                return netValue.getRRInThreeYear();
            case 8:
                return netValue.getRRSinceThisYear();
            case 9:
                return netValue.getRRSinceStart();
            default:
                return netValue.getNVDailyGrowthRate();
        }
    }


    /**
     * 获取基金的品牌
     *
     * @param fundCode
     * @return
     */
    public static String getT0FundBrandsType(String fundCode) {
        String brandsType;
        if (FundUtil.isBaoYingT0AB(fundCode)) {
            brandsType = GlobalConstant.T0_FUND_BAOYING;
        } else if (FundUtil.isJinYingT0AB(fundCode)) {
            brandsType = GlobalConstant.T0_FUND_JINYING;
        } else if (FundUtil.isChangChengT0AB(fundCode)) {
            brandsType = GlobalConstant.T0_FUND_CHANGCHENG;
        } else {
            log.error("没有找到对应的基金品牌");
            brandsType = "UNKONWN";
        }

        return brandsType;
    }


    public static boolean isBaoYingT0AB(String fundCode) {
        return EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_BAOYING_A) ||
            EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_BAOYING_B);
    }

    public static boolean isJinYingT0AB(String fundCode) {
        return EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_JINYING_A)
            || EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_JINYING_B)
            || EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_JINYING2_A)
            || EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_JINYING2_B);
    }

    public static boolean isChangChengT0AB(String fundCode) {
        return EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_CHANGCHENG_A) ||
            EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_CHANGCHENG_B) || EqualsUtil.equals(fundCode, GlobalConstant.T0_FUND_CHANGCHENG_E);
    }


}
